class SetRootEvents < ActiveRecord::Migration
  def self.up
    event_default = Event.find_by_type_and_name_and_parent_id(nil, "Default", nil)
    if event_default
      event_default.destroy
    end
    boss_default = BossEvent.find_or_create_by_name("Bosses")
    bonus_default = RaidBonusEvent.find_or_create_by_name("Bonuses")
    hours_default = HoursEvent.find_or_create_by_name("Hours")
    BossEvent.find(:all).each do |event|
      event.parent = boss_default
      event.save
    end
    RaidBonusEvent.find(:all).each do |event|
      event.parent = bonus_default
      event.save
    end
    HoursEvent.find(:all).each do |event|
      event.parent = hours_default
      event.save
    end
    boss_default.parent = nil
    boss_default.save
    bonus_default.parent = nil
    bonus_default.save
    hours_default.parent = nil
    hours_default.save
  end

  def self.down
    raise IrreversibleMigration
  end
end
